<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="司机姓名" prop="name">
        <el-input
          :style="{ width: '150px' }"
          maxlength="20"
          v-model="queryParams.name"
          placeholder="请输入司机姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="司机电话" prop="mobile">
        <el-input
          :style="{ width: '150px' }"
          v-model="queryParams.mobile"
          placeholder="请输入司机电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车牌号码" prop="carNumber">
        <el-input
        :style="{ width: '150px' }"
          v-model="queryParams.carNumber"
          placeholder="请输入车牌号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="到期状态" prop="expireStatus">
        <el-select
          v-model="queryParams.expireStatus"
          placeholder="请选择到期状态"
          clearable
        >
          <el-option
            v-for="dict in dict.type.car_job_expirestatus"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['tms:driver:add']"
          >新增</el-button
        >
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['tms:driver:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['tms:driver:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      :border="true"
      v-loading="huanchong"
      :row-class-name="tableRowClassName"
      :data="driverList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" width="50" align="center" prop="id" />
      <el-table-column label="司机姓名" align="center" prop="name" />
      <el-table-column label="车牌号码" align="center" prop="carName" />
      <el-table-column label="司机电话" align="center" prop="mobile" />
      <el-table-column label="司机年龄(岁)" align="center" prop="age" />
      <el-table-column label="司机驾龄(年)" align="center" prop="licenseAge" />
      <el-table-column
        label="司机驾驶证编号"
        align="center"
        prop="licenseNumber"
      />
      <el-table-column
        label="司机到期状态"
        align="center"
        prop="expireStatus"
        width="100"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.car_job_expirestatus"
            :value="scope.row.expireStatus"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-d-arrow-right"
            @click="handleView(scope.row)"
            v-hasPermi="['tms:driver:remove']"
            >查看更多</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['tms:driver:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加司机信息对话框 -->
    <el-dialog
      @close="closeDialog"
      :title="title"
      :visible.sync="open"
      width="790px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="司机姓名" prop="name">
              <el-input
                maxlength="20"
                v-model="form.name"
                placeholder="请输入司机姓名"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="司机电话" prop="mobile">
              <el-input
                maxlength="20"
                v-model="form.mobile"
                placeholder="请输入司机电话"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="司机年龄(岁)" prop="age">
              <el-input
                maxlength="20"
                v-model="form.age"
                placeholder="请输入司机年龄"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="司机驾龄(年)" prop="licenseAge">
              <el-input-number
                maxlength="20"
                v-model="form.licenseAge"
                controls-position="right"
                :min="1"
              ></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="司机驾驶证编号" prop="licenseNumber">
              <el-input
                maxlength="20"
                v-model="form.licenseNumber"
                placeholder="请输入司机驾驶证编号"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="驾驶证类型" prop="licenseType">
              <el-select
                v-model="form.licenseType"
                placeholder="请选择驾驶证类型"
              >
                <el-option
                  v-for="item in testList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="初次领证日期" prop="licenseStartTime">
              <el-date-picker
                clearable
                v-model="form.licenseStartTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择初次领证日期"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="驾驶证有效期限" prop="licenseValidTime">
              <el-date-picker
                clearable
                v-model="form.licenseValidTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择驾驶证有效期限"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 绑定车辆 -->
        <el-row>
          <el-form-item label="绑定车辆" prop="carName">
            <el-select
              clearable
              v-model="form.carId"
              filterable
              placeholder="请选择车辆"
            >
              <el-option
                v-for="item in options"
                :key="item.id"
                :label="item.carNumber"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="司机照片" prop="avatar">
            <el-upload
              v-loading="huanchong"
              :limit="2"
              action="files.kylebing.cn"
              list-type="picture-card"
              :on-preview="handlePictureCardPreview"
              :on-success="handleSwiperSuccess"
              :http-request="driverImgFile"
              :on-remove="handleRemoveSiji"
              :file-list="driverImg"
              :on-exceed="tishi"
              accept=".jpeg,.png,.jpg,.bmp"
              :before-upload="checkFileType"
            >
              <i class="el-icon-plus"></i>
              <div slot="tip" class="el-upload__tip" style="color: red">
                只能上传jpeg/png/jpg/bmp文件，且不超过500kb
              </div>
            </el-upload>
            <el-dialog :modal="false" :visible.sync="dialogVisible">
              <img width="100%" :src="dialogImageUrl" alt="" />
            </el-dialog>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="行驶证照片" prop="licenseImgUrl">
            <el-upload
              v-loading="huanchong"
              :limit="2"
              action="files.kylebing.cn"
              list-type="picture-card"
              :on-preview="handlePictureCardPreview"
              :on-success="handleSwiperSuccess"
              :http-request="uploadFile"
              :on-remove="handleRemove"
              :file-list="fileList"
              :on-exceed="tishi"
              accept=".jpeg,.png,.jpg,.bmp"
              :before-upload="checkFileType"
            >
              <i class="el-icon-plus"></i>
              <div slot="tip" class="el-upload__tip" style="color: red">
                只能上传jpeg/png/jpg/bmp文件，且不超过500kb
              </div>
            </el-upload>
            <el-dialog :modal="false" :visible.sync="dialogVisible">
              <img width="100%" :src="dialogImageUrl" alt="" />
            </el-dialog>
          </el-form-item>
        </el-row>

        <el-form-item label="备注" prop="remark">
          <el-input
            maxlength="500"
            v-model="form.remark"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm()">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 员工基本信息 -->
    <el-dialog
      @close="closeDialog"
      title="基本信息"
      :visible.sync="openView"
      width="700px"
      append-to-body
    >
      <el-form
        ref="form"
        :rules="rules"
        :model="form"
        label-width="120px"
        size="mini"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="司机姓名" prop="name">
              <el-input v-model="form.name" placeholder="请输入司机姓名" />
            </el-form-item>
            <el-form-item label="司机电话" prop="mobile">
              <el-input maxlength="20" v-model="form.mobile" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="司机年龄(岁)" prop="age">
              <el-input maxlength="20" v-model="form.age" />
            </el-form-item>
            <el-form-item label="司机驾龄(年)" prop="licenseAge">
              <!-- <el-input v-model="form.licenseAge" /> -->
              <el-input-number
                maxlength="20"
                v-model="form.licenseAge"
                controls-position="right"
                :min="1"
              ></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="司机照片" prop="avatar">
            <el-upload
              accept=".jpeg,.png,.jpg,.bmp"
              v-loading="huanchong"
              action="files.kylebing.cn"
              list-type="picture-card"
              :on-preview="handlePictureCardPreview"
              :on-remove="removeChangesiji"
              :http-request="driverImgFile"
              :file-list="driverImg"
              :on-exceed="tishi"
              :limit="2"
              :before-upload="checkFileType"
            >
              <i class="el-icon-plus"></i>
              <div slot="tip" class="el-upload__tip" style="color: red">
                只能上传jpeg/png/jpg/bmp文件，且不超过500kb
              </div>
            </el-upload>
            <el-dialog :modal="false" :visible.sync="dialogVisible">
              <img width="100%" :src="dialogImageUrl" alt="" />
            </el-dialog>
          </el-form-item>
        </el-row>
        <!-- 驾驶证信息 -->
        <el-row>
          <h3 class="jiashi">驾驶证信息</h3>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="驾驶证类型" prop="licenseType">
              <el-select
                width="55"
                v-model="form.licenseType"
                placeholder="请选择驾驶证类型"
              >
                <el-option
                  v-for="item in testList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="绑定车辆" prop="carName">
              <el-select
                clearable
                v-model="form.carId"
                filterable
                placeholder="请选择车辆"
              >
                <el-option
                  v-for="item in options"
                  :key="item.id"
                  :label="item.carNumber"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="初次领证日期" prop="licenseStartTime">
              <el-date-picker
                clearable
                v-model="form.licenseStartTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择初次领证日期"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="驾驶证有效期限" prop="licenseValidTime">
              <el-date-picker
                clearable
                v-model="form.licenseValidTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择驾驶证有效期限"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="司机驾驶证编号" prop="licenseNumber">
              <el-input maxlength="50" v-model="form.licenseNumber" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="行驶证照片" prop="licenseImgUrl">
            <el-upload
              accept=".jpeg,.png,.jpg,.bmp"
              v-loading="huanchong"
              action="files.kylebing.cn"
              list-type="picture-card"
              :on-preview="handlePictureCardPreview"
              :on-remove="removeChange"
              :http-request="uploadFile"
              :file-list="fileList"
              :on-exceed="tishi"
              :limit="2"
              :before-upload="checkFileType"
            >
              <i class="el-icon-plus"></i>
              <div slot="tip" class="el-upload__tip" style="color: red">
                只能上传jpeg/png/jpg/bmp文件，且不超过500kb
              </div>
            </el-upload>
            <el-dialog :modal="false" :visible.sync="dialogVisible">
              <img width="100%" :src="dialogImageUrl" alt="" />
            </el-dialog>
          </el-form-item>
        </el-row>
        <el-form-item label="备注" prop="remark">
          <el-input
            maxlength="500"
            v-model="form.remark"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">保存</el-button>
        <el-button @click="colse">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listDriver,
  getDriver,
  delDriver,
  addDriver,
  updateDriver,
  getCar,
  fileBang,
} from "@/api/tms/driver";
import { getQnToken } from "@/api/system/user";
import * as qiniu from "qiniu-js";
export default {
  dicts: ["car_job_expirestatus"],
  name: "Driver",
  data() {
    return {
      // 显示缓冲状态
      huanchong: false,
      // 是否显示cropper
      visible: false,
      previews: {},
      qnData: {},
      testList: [
        {
          label: "A1",
          value: 1,
        },
        {
          label: "A2",
          value: 2,
        },
        {
          label: "A3",
          value: 3,
        },
        {
          label: "B1",
          value: 4,
        },
        {
          label: "B2",
          value: 5,
        },
        {
          label: "C1",
          value: 6,
        },
        {
          label: "C2",
          value: 7,
        },
        {
          label: "C3",
          value: 8,
        },
      ],
      options: [],
      value: "",
      disabled: false,
      status: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 司机信息表格数据
      driverList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示详细弹出层
      openView: false,

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        carId: null,
        userId: null,
        name: null,
        mobile: null,
        age: null,
        carNumber: null,
        licenseAge: null,
        licenseNumber: null,
        licenseType: null,
        licenseStartTime: null,
        licenseValidTime: null,
        deleted: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "司机姓名不能为空", trigger: "blur" },
        ],
        mobile: [
          { required: true, message: "司机电话不能为空", trigger: "blur" },
          { pattern: /^[0-9]*$/, message: "司机电话输入有误", trigger: "blur" },
        ],
        age: [
          { required: false, trigger: "blur" },
          { pattern: /^[0-9]*$/, message: "年龄需为数字", trigger: "blur" },
        ],
        licenseAge: [
          { required: true, message: "司机驾龄不能为空", trigger: "blur" },
          { pattern: /^[0-9]*$/, message: "驾龄需为数字", trigger: "blur" },
        ],
        licenseNumber: [
          {
            required: true,
            message: "司机驾驶证编号不能为空",
            trigger: "blur",
          },
        ],
        licenseStartTime: [
          { required: true, message: "初次领证日期不能为空", trigger: "blur" },
        ],
        licenseValidTime: [
          {
            required: true,
            message: "驾驶证有效期限不能为空",
            trigger: "blur",
          },
        ],
      },
      dialogImageUrl: "",
      dialogVisible: false,
      fileList: [],
      driverName: "",
      driverUrl: "",
      urlKey: [],
      driverImg: [],
      sijiName: "",
      sijiUrl: "",
      sijiKey: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 限制上传图片类型
    checkFileType(file) {
      // console.log(file);
      let fileName = file.name;
      let fileType = fileName.substring(fileName.lastIndexOf("."));
      let fileSize = file.size / 1024;
      if (fileSize > 500) {
        this.$message.error("图片过大，请重新选择");
      }
    },
    closeDialog() {
      this.fileList = [];
      this.urlKey = [];
      this.driverImg = [];
      this.sijiKey = [];
    },
    // 上传图片
    async uploadFile(uploadInfo) {
      // console.log(uploadInfo);
      let response = await this.getQnToken();
      // console.log(response);
      if (response.code == 200) {
        this.qnData.token = response.data.token;
        let config = {
          useCdnDomain: true,
          region: qiniu.region.z0,
        };
        let putExtra = {
          fname: this.qnData.key,
          params: {},
          mimeType: null,
        };
        var observable = qiniu.upload(
          uploadInfo.file,
          response.data.qiniuKey,
          this.qnData.token,
          putExtra,
          config
        );

        observable.subscribe({
          next: (res) => {
            if (res.total.percent != 100) {
              this.huanchong = true;
            } else {
              this.huanchong = false;
            }
          },
          complete: (result) => {
            let avatar = `http://img.mofankj.com/${result.key}`;
            let data = {
              avatar,
            };
            this.driverName = result.key;
            this.driverUrl = data.avatar;
            this.fileList.push({
              name: this.driverName,
              url: this.driverUrl,
            });

            this.urlKey.push({
              fileName: uploadInfo.file.name,
              url: result.key,
              key: data.avatar,
            });
            let params = {
              fileName: uploadInfo.file.name,
              key: result.key,
            };
            fileBang(params).then((res) => {});
          },
        });
      }
    },
    // 上传司机照片
    async driverImgFile(uploadInfo) {
      let response = await this.getQnToken();
      if (response.code == 200) {
        this.qnData.token = response.data.token;
        let config = {
          useCdnDomain: true,
          region: qiniu.region.z0,
        };
        let putExtra = {
          fname: this.qnData.key,
          params: {},
          mimeType: null,
        };
        var observable = qiniu.upload(
          uploadInfo.file,
          response.data.qiniuKey,
          this.qnData.token,
          putExtra,
          config
        );

        observable.subscribe({
          next: (res) => {
            if (res.total.percent != 100) {
              this.huanchong = true;
            } else {
              this.huanchong = false;
            }
          },
          complete: (result) => {
            let avatar = `http://img.mofankj.com/${result.key}`;
            let data = {
              avatar,
            };
            this.sijiName = result.key;
            this.sijiUrl = data.avatar;
            this.driverImg.push({
              name: this.sijiName,
              url: this.sijiUrl,
            });
            this.sijiKey.push({
              fileName: uploadInfo.file.name,
              url: result.key,
              key: data.avatar,
            });
            console.log(this.fil);
            let params = {
              fileName: uploadInfo.file.name,
              key: result.key,
            };
            fileBang(params).then((res) => {});
          },
        });
      }
    },
    // 添加信息时移除照片
    handleRemove(file) {
      this.fileList.forEach((value, index, array) => {
        if (file.uid == value.uid) {
          array.splice(index, 1);
        }
      });
      this.urlKey.forEach((value, index, array) => {
        if (file.name == value.url) {
          array.splice(index, 1);
        }
      });
    },
    // 添加信息时移除司机照片
    handleRemoveSiji(file) {
      this.driverImg.forEach((value, index, array) => {
        if (file.uid == value.uid) {
          array.splice(index, 1);
        }
      });
      this.sijiKey.forEach((value, index, array) => {
        if (file.name == value.url) {
          array.splice(index, 1);
        }
      });
    },
    // 修改信息时移除照片
    removeChange(file) {
      this.fileList.forEach((value, index, array) => {
        if (file.uid == value.uid) {
          array.splice(index, 1);
        }
      });
      this.urlKey.forEach((value, index, array) => {
        if (file.name == value.fileName || file.name == value.url) {
          array.splice(index, 1);
        }
      });
    },
    // 修改信息时移除司机照片
    removeChangesiji(file) {
      this.driverImg.forEach((value, index, array) => {
        if (file.uid == value.uid) {
          array.splice(index, 1);
        }
      });
      this.sijiKey.forEach((value, index, array) => {
        if (file.name == value.fileName || file.name == value.url) {
          array.splice(index, 1);
        }
      });
    },
    colse() {
      this.openView = false;
      this.fileList = [];
      this.urlKey = [];
      this.driverImg = [];
      this.sijiKey = [];
    },
    // 放大照片
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    //下载照片
    handleDownload(file) {
      // console.log(file);
    },
    // 新增信息照片上限
    tishi() {
      this.$message.error("数量已经超过上限，无法继续上传！");
    },
    handleSwiperSuccess() {},
    handleView(row) {
      // 获取车牌号信息
      getCar().then((res) => {
        this.options = res.data;
      });
      this.reset();
      const id = row.id || this.ids;
      getDriver(id).then((response) => {
        for (let i = 0; i < response.data.licenseImgs.length; i++) {
          this.fileList.push({
            name: response.data.licenseImgs[i].fileName,
            url: response.data.licenseImgs[i].fileUrl,
          });
          this.urlKey.push({
            fileName: response.data.licenseImgs[i].fileName,
            url: response.data.licenseImgs[i].qiniuKey,
          });
        }
        for (let i = 0; i < response.data.avatas.length; i++) {
          this.driverImg.push({
            name: response.data.avatas[i].fileName,
            url: response.data.avatas[i].fileUrl,
          });
          this.sijiKey.push({
            fileName: response.data.avatas[i].fileName,
            url: response.data.avatas[i].qiniuKey,
          });
        }
        this.form = response.data;
        if (this.form.carId == 0) {
          this.form.carId = null;
        }
        if (this.form.licenseType == 0) {
          this.form.licenseType = null;
        }
        this.openView = true;
      });
    },
    // 表单隔行变色
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return "success-row";
      } else {
        return "warning-row";
      }
    },
    /** 查询司机信息列表 */
    getList() {
      this.loading = true;
      listDriver(this.queryParams).then((response) => {
        this.driverList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.fileList = [];
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        carId: null,
        userId: null,
        name: null,
        mobile: null,
        age: null,
        licenseAge: null,
        licenseNumber: null,
        licenseType: null,
        licenseStartTime: null,
        licenseValidTime: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        deleted: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      getCar().then((res) => {
        this.options = res.data;
      });
      this.reset();
      this.open = true;
      this.title = "添加司机信息";
    },
    /** 提交按钮 */
    submitForm() {
      //  / 上传的车辆照片
      if (this.urlKey.length > 0) {
        let list = [];
        for (let i = 0; i < this.urlKey.length; i++) {
          list.push(this.urlKey[i].url);
          this.form.licenseImgUrl = list + "";
        }
      } else {
        this.form.licenseImgs = [];
        this.form.licenseImgUrl = "";
      }
      //  / 上传的司机照片
      if (this.sijiKey.length > 0) {
        let list = [];
        for (let i = 0; i < this.sijiKey.length; i++) {
          list.push(this.sijiKey[i].url);
          this.form.avatar = list + "";
        }
      } else {
        this.form.avatarImgs = [];
        this.form.avatar = "";
      }
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            if (!/^1(3|4|5|7|8)\d{9}$/.test(this.form.mobile)) {
              this.$message.error("您的手机号码不正确，请重新填写！");
            } else {
              updateDriver(this.form).then((response) => {
                this.$modal.msgSuccess("修改成功");
                this.openView = false;
                this.open = false;
                this.getList();
              });
            }
          } else {
            if (!/^1(3|4|5|7|8)\d{9}$/.test(this.form.mobile)) {
              this.$message.error("您的手机号码不正确，请重新填写！");
            } else {
              addDriver(this.form).then((response) => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.fileList = [];
                this.getList();
              });
            }
          }
        }
      });
    },
    /** 获取七牛云token */
    getQnToken() {
      return new Promise((resolve, reject) => {
        getQnToken().then((response) => {
          resolve(response);
        });
      });
    },
    // 实时预览
    realTime(data) {
      this.previews = data;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除车辆信息编号为"' + ids + '"的数据项？')
        .then(function () {
          return delDriver(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "tms/driver/export",
        {
          ...this.queryParams,
        },
        `driver_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style>
.el-table .warning-row {
  background: #f7faff;
}
.el-table .success-row {
  background: #ebf1fb;
}
.jiashi {
  margin-top: 40px;
  margin-bottom: 30px;
}
</style>
